package com.auxgroup.hr.front.site.co.modPerson;

import javax.annotation.Resource;

import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.BaseRetCode;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModJcxx;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.modperson.ModJcxxService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;

/**
 * 奖惩情况流程信息CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/modJcxx")
public class ModJcxxCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(ModJcxxCO.class);

	@Autowired
	public ModJcxxService modJcxxService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 保存奖惩情况流程信息
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(PsCModJcxx modJcxx,@SessionGain("user") UserDTO user) {
		logger.info("saveModJcxx param= {}", modJcxx);
		if(StringUtils.isBlank(modJcxx.getcTransactionNbr())){
			return buildRespone(BaseRetCode.CODE_ERROR_REQUEST_PARAM_NULL.getRetCode(), "流程编号不能为空");
		}
		if(StringUtils.isBlank(modJcxx.getEmplid())){
			return buildRespone(BaseRetCode.CODE_ERROR_REQUEST_PARAM_NULL.getRetCode(), "员工ID不能为空");
		}
		if(StringUtils.isBlank(modJcxx.getcModStauts())){
			return buildRespone(BaseRetCode.CODE_ERROR_REQUEST_PARAM_NULL.getRetCode(), "数据状态不能为空");
		}
		if(modJcxx.getcSeqno()!=null){
			PsCModPerPrimary primary = new PsCModPerPrimary();
			primary.setcTransactionNbr(modJcxx.getcTransactionNbr());
			primary.setEmplid(modJcxx.getEmplid());
			primary.setcSeqno(modJcxx.getcSeqno());
			PsCModJcxx nowJcxx = modJcxxService.getModJcxx(primary);
			if(nowJcxx!=null){
				objectMapper.map(modJcxx, nowJcxx,"notCopyNull_modJcxx");
				modJcxx = modJcxxService.save(nowJcxx,user);
			}else{
				modJcxx = modJcxxService.save(modJcxx,user);
			}
		}else{
			modJcxx = modJcxxService.save(modJcxx,user);
		}
		if(modJcxx.getcSeqno()!=null){
			return buildRespone(true);
		}
		return buildRespone(false);
	}
	
	/**
	 * 获取奖惩情况流程信息
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(PsCModPerPrimary modPerPrimary) {
		logger.info("getModJcxx param= {}", modPerPrimary);
		PsCModJcxx modJcxx = modJcxxService.getModJcxx(modPerPrimary);
		return buildRespone(modJcxx);
	}
	
}
